package org.javaboy.vhr.controller.salary;

import org.javaboy.vhr.model.AdjustSalary;
import org.javaboy.vhr.service.AdjustSalaryService;
import org.javaboy.vhr.vo.RespBean;
import org.javaboy.vhr.vo.RespPageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * Author: cheng
 */
@RestController
@RequestMapping("/salary/adjustSalary")
public class AdjustSalaryController {
    @Autowired
    AdjustSalaryService adjustSalaryService;
    @GetMapping("/")
    public RespPageBean getSalaryByPage(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer size, AdjustSalary adjustSalary, Date[] beginDateScope) {
        return adjustSalaryService.getAdjSalByPage(page,size,adjustSalary,beginDateScope);
    }

    @PostMapping("/add")
    public RespBean add(@RequestBody AdjustSalary adjustSalary){
        Integer i = adjustSalaryService.add(adjustSalary);
        if(i == null) {
            return RespBean.error("操作失败");
        }else return RespBean.ok("操作成功");
    }

    @PutMapping("/update")
    public RespBean updateEmp(@RequestBody AdjustSalary adjustSalary) {
        int result = adjustSalaryService.update(adjustSalary);
        if(result==0) return RespBean.error("操作失败");
        else return RespBean.ok("操作成功");
    }

    @DeleteMapping("/{id}")
    public RespBean deleteEcById(@PathVariable Integer id) {
        int result = adjustSalaryService.delete(id);
        if(result==0) return RespBean.error("操作失败");
        else return RespBean.ok("操作成功");
    }


}
